import React, {Component} from 'react';

class Index extends Component {
    state = {
        count: 0
    }
    add = () => {
        // 对象式
        // const {count} = this.state
        // this.setState({count:count+1},()=>{
        //     console.log(this.state.count) // 1
        // })
        // console.log(this.state.count) // 0
        // 函数式
        this.setState((state, props) => {
            console.log(state, props)
            return {count: state.count + 1}
        }, () => {
            console.log(this.state.count) // 99
        })
    }

    render() {
        return (
            <div>
                <h1>当前求和为：{this.state.count}</h1>
                <button onClick={this.add}>加</button>
            </div>
        );
    }
}

export default Index;